import 'package:get/get.dart';
import 'package:school_assistant_m/config/config.dart';
import 'package:school_assistant_m/utils/my_http.dart';

/// jerry: 重新封装请求方式，原请求方式在controller中第二次刷新界面才能获取数据
class BaseApi extends GetConnect {
  @override
  void onInit() {
    httpClient.baseUrl = BASE_URL;
    // 请求拦截
    httpClient.addRequestModifier<void>((request) async {
      request.headers["Authorization"] = await MyHttp.addGetAuthorization();
      return request;
    });

    // 响应拦截
    httpClient.addResponseModifier((request, response) {
      // 处理逻辑
      return response;
    });
  }
}
